package com.itic.ht.mem.memberdetail.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.HtCrudService;
import com.itic.ht.mem.member.persistence.model.WebMember;
import com.itic.ht.mem.memberdetail.persistence.dao.WebMemberDetailDao;
import com.itic.ht.mem.memberdetail.persistence.model.WebMemberDetail;
import com.itic.ht.mem.memberdetail.persistence.model.WebMemberDetailExample;
import com.itic.ht.mem.memberdetail.persistence.model.WebMemberDetailExample.Criteria;


@Service
@Transactional
public class WebMemberDetailService
     extends HtCrudService<WebMemberDetailDao,WebMemberDetail,WebMemberDetailExample> {
    @Autowired
    private WebMemberDetailDao webMemberDetailDao;

	public String deltrue(Integer id) {
		int result = webMemberDetailDao.deleteByPrimaryKey(id);
		if(result>0){
    		return SUCCESS;
    	}else{
    		return FAILED;
    	}
	}
	public WebMemberDetail getMemberDetailByAccount(String account) {
		WebMemberDetail memberDetail = null;
		try {
			WebMemberDetailExample example = new WebMemberDetailExample();
			example.createCriteria().andAccountEqualTo(account).andDelFlagEqualTo(Integer.parseInt(DBConst.TRUE));
			List<WebMemberDetail> list = webMemberDetailDao.selectByExample(example);
			if(list !=null && list.size()>0){
				memberDetail = list.get(0);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return memberDetail;
		
	}
	
	
	public String deleteOther(WebMember temp) {
		WebMemberDetailExample example = new WebMemberDetailExample();
		Criteria criteria = example.createCriteria();
		criteria.andAccountEqualTo(temp.getAccount());
		
		WebMemberDetail memberDetail = new WebMemberDetail();
		memberDetail.setDelFlag(0);
		
		webMemberDetailDao.updateByExampleSelective(memberDetail, example);
		return SUCCESS;
	}

}